//
//  GroupApplyVerityTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/1.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "GroupApplyVerityTableViewCell.h"

@implementation GroupApplyVerityTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 头像
    self.friendImageV = [[UIImageView alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 15 * kAdjustParamater, 50 * kAdjustParamater, 50 * kAdjustParamater)];
    self.friendImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.friendImageV.layer.cornerRadius = self.friendImageV.width / 2;
    self.friendImageV.layer.masksToBounds = YES;
    [self.contentView addSubview:_friendImageV];
    
    // 入群消息
    self.groupMessageLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.friendImageV.right + 6 * kAdjustParamater, self.friendImageV.top , 100 * kAdjustParamater, 14 * kAdjustParamater)];
    // self.friendMessage.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.groupMessageLabel.text = @"入群消息";
    self.groupMessageLabel.textColor = [UIColor blackColor];
    self.groupMessageLabel.textAlignment = NSTextAlignmentLeft;
    self.groupMessageLabel.font = [UIFont systemFontOfSize:k14Big];
    [self.contentView addSubview:_groupMessageLabel];
    
    // 姓名
    self.friendNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.friendImageV.right + 6 * kAdjustParamater, self.groupMessageLabel.bottom + 7 * kAdjustParamater, 150 * kAdjustParamater, 12 * kAdjustParamater)];
    //  self.friendNameLabel.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.friendNameLabel.textColor = [UIColor blackColor];
    self.friendNameLabel.textAlignment = NSTextAlignmentLeft;
    self.friendNameLabel.font = [UIFont systemFontOfSize:k13Big];
    [self.contentView addSubview:_friendNameLabel];
    
    // 留言
    self.liuYanLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.friendNameLabel.left, self.friendNameLabel.bottom + 5 * kAdjustParamater, 250 * kAdjustParamater, 12 * kAdjustParamater)];
    // self.liuYanLabel.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.liuYanLabel.textAlignment = NSTextAlignmentLeft;
    self.liuYanLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.liuYanLabel.font = [UIFont systemFontOfSize:k13Big];
    self.liuYanLabel.numberOfLines = 0;
    [self.contentView addSubview:_liuYanLabel];
    
    // 同意或者忽略按钮
    self.agreeOrIngoreButton = [UIButton buttonWithType:UIButtonTypeSystem];
    //  self.agreeOrIngoreButton.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.1];
    self.agreeOrIngoreButton.frame = CGRectMake((375 - 80) * kAdjustParamater, 27 * kAdjustParamater, 70 * kAdjustParamater, 25 * kAdjustParamater);
    self.agreeOrIngoreButton.titleLabel.font = [UIFont systemFontOfSize:k15Big];
    [self.contentView addSubview:_agreeOrIngoreButton];
    
    
    
    
    
}

- (void)setModel:(GroupApplyVerityModel *)model
{
    self.friendNameLabel.text = model.name;
    self.liuYanLabel.text = model.groupLiuYan;
    // 进行自适应高度
    CGRect liuYanLabelNewFrame = self.liuYanLabel.frame;
    liuYanLabelNewFrame.size.height = [[NetStatusHandle shareHandle] adjustHeight:self.liuYanLabel.text size:13 width:250];
    self.liuYanLabel.frame = liuYanLabelNewFrame;
    
    // 判断同意或者不同意
    if ([model.isHaveAgree isEqualToString:@"NO"]) {
        //说明还没有同意,按钮需要打开
        [self.agreeOrIngoreButton setTitle:@"同意" forState:UIControlStateNormal];
        [self.agreeOrIngoreButton setTitleColor:kYellowColor forState:UIControlStateNormal];
        self.agreeOrIngoreButton.layer.cornerRadius = 3 * kAdjustParamater;
        self.agreeOrIngoreButton.layer.borderColor = [[[UIColor blackColor] colorWithAlphaComponent:0.1] CGColor];
        self.agreeOrIngoreButton.layer.borderWidth = 1 * kAdjustParamater;
        self.agreeOrIngoreButton.userInteractionEnabled = YES;
    } else if ([model.isHaveAgree isEqualToString:@"YES"]) {
        // 说明已经同意，按钮需要关闭
        [self.agreeOrIngoreButton setTitle:@"已同意" forState:UIControlStateNormal];
        [self.agreeOrIngoreButton setTitleColor:[[UIColor blackColor]colorWithAlphaComponent:0.5]  forState:UIControlStateNormal];
        // 应该取消外围
        self.agreeOrIngoreButton.layer.borderColor = [[UIColor whiteColor] CGColor];
        self.agreeOrIngoreButton.userInteractionEnabled = NO;
    }
}


@end
